/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.wider.foundation;

/**
 * Helper class which helps user to maintain a manager of sequence numbering.
 * This class implements a wrapped numbering system.
 * 
 * @author William Choi <avextk@gmail.com>
 */
public class Numbering {
    final long x;
    final long y;
    long n;

    /**
     * Public constructor for user to construct an instance of Numbering
     * @param start     The start index of a Numbering
     * @param end       The end index of a Numbering. When the "end" is reached, the Numbering will wrapp back to the start.
     */
    public Numbering(long start, long end){
        x = start;
        y = end;
        n = -1;
    }

    /**
     * Public method for user to get the next number of a Numbering
     * @return  The next number
     */
    public long next(){
        n = ++n % (y - x + 1);

        return n + x;
    }
}
